#!/usr/bin/env python
#
#   Copyright (C) 2006 Jonathan Saggau                                     
#   saggau@gmail.com                                                       
#                                                                          
#   This program is free software; you can redistribute it and/or modify  
#   it under the terms of the GNU General Public License as published by  
#   the Free Software Foundation; either version 2 of the License, or     
#   (at your option) any later version.                                    
#                                                                          
#   This program is distributed in the hope that it will be useful,        
#   but WITHOUT ANY WARRANTY; without even the implied warranty of        
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         
#   GNU General Public License for more details.                          
#                                                                          
#   You should have received a copy of the GNU General Public License     
#   along with this program; if not, write to the                         
#   Free Software Foundation, Inc.,                                        
#   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  
#

from loader import Loader
from supyrconductor import node

class Controller(Loader):
    """Sends necessary msgs to server both to load and modify attributes
       of a given trigger synth"""
    
    def __init__(self, controller, nodeID, bufferID):
        Loader.__init__(self, controller, nodeID, bufferID)
        self._loadSynth()
        self.panIsActive = False #bool
        
    def _set(self, arg, val):
        self.controller.listSendMsg(node.set(self.nodeID, {arg:val}))
        
    def close(self):
        self._unloadSynth()
        
    def __del__(self):
        self.close()
        
    def setInput(self, input):
        Loader.setInput(self, input)
        self._set('in', input)

    def setTriggerID(self, trigID):
        Loader.setTriggerID(self, trigID)
        self._set('triggerID', trigID)

    def setEnvCurve(self, curve):
        Loader.setEnvCurve(self, curve)
        self._set('envCurve', curve)

    def setPan(self, pan): # from -1 to 1
        Loader.setPan(self, pan)
        self._set('pan', pan)

    def setVolume(self, vol):
        Loader.setVolume(self, vol)
        self._set('amp', vol)

    def setSampleDuration(self, duration):
        Loader.setSampleDuration(self, duration)
        self._set('duration', duration)

    def setSensitivity(self, sensitivity):
        Loader.setSensitivity(self, sensitivity)
        self._set('thresh', sensitivity)

    def setOut(self, out):
        Loader.setOut(self, out)
        self._set('outBus', out)

    def setBufferID(self, id):
        Loader.setBufferID(self, id)
        self._set("bufnum", id)

    def setBufferPosition(self, position): #(in frames)
        Loader.setBufferPosition(self, position)
        self._set('bufferPosition', position)

    def setAttackSharpness(self, sharpness): 
        """actually this is attack duration, 
           but it's heard as sharpness"""
        Loader.setAttackSharpness(self, sharpness)
        self._set('attackDuration', sharpness)